import mongoose, { Document, Schema } from 'mongoose';
import { ITeam } from './Team'; // 交叉引用类型

export interface IUser extends Document {
  username: string;
  email: string;
  password?: string; // 密码是可选的，因为我们通常不返回它
  role: 'member' | 'admin';
  teams: (ITeam['_id'])[];
}

const UserSchema: Schema = new Schema({
  username: { type: String, required: true, unique: true },
  email: { type: String, required: true, unique: true },
  password: { type: String, required: true },
  role: { type: String, enum: ['member', 'admin'], default: 'member' },
  teams: [{ type: Schema.Types.ObjectId, ref: 'Team' }]
}, { timestamps: true });

export default mongoose.model<IUser>('User', UserSchema);